const dict = {
  state: {
    routerList: [], // 路由栏 [ {name: , title, isActive}, ...]

    sidebarMenu: [
      {
        title: "系统管理",
        icon: "el-icon-user",
        isShow: false,
        children: [
          { isShow: false, name: "origin", path: "/origin", title: "区域管理" },
          { isShow: false, name: "device", path: "/device", title: "设备管理" },
          { isShow: false, name: "user", path: "/user", title: "用户管理" },
        ],
      },
      {
        title: "权限管理",
        icon: "el-icon-warning-outline",
        isShow: false,
        children: [
          { isShow: false, name: "role", path: "/role", title: "角色管理" },
        ],
      },
      {
        title: "日志数据",
        icon: "el-icon-printer",
        isShow: false,
        children: [
          {
            isShow: false,
            name: "opendoorlog",
            path: "/opendoorlog",
            title: "开门日志",
          },
          {
            isShow: false,
            name: "alarmlog",
            path: "/alarmlog",
            title: "报警日志",
          },
          {
            isShow: false,
            name: "operlog",
            path: "/operlog",
            title: "平台操作",
          },
        ],
      },
      {
        title: "系统配置",
        icon: "el-icon-setting",
        isShow: false,
        children: [
          { isShow: false, name: "config", path: "/config", title: "配置" },
        ],
      },
    ],
  },

  mutations: {
    // 路由栏 - 添加路由
    PUSH_ROUTER(state, arr) {
      if (arr.name == "login") return
      let addFlag = true;
      for (let route of state.routerList) {
        if (route.name == arr.name) {
          addFlag = false;
          route.isActive = true;
        } else if (route.isActive) {
          route.isActive = false;
        }
      }
      if (addFlag) {
        state.routerList.push({
          name: arr.name,
          title: arr.title,
          isActive: true,
        });
      }
      return;
    },
    // 路由栏 - 删除路由
    DEL_ROUTER(state, name) {
      let index = -1,
        i = 0;
      for (let route of state.routerList) {
        if (route.name == name) {
          index = i;
        }
        i++;
      }
      if (index > -1) {
        state.routerList.splice(index, 1);
      }
      return;
    },
    // 路由栏 - 点击路由
    SET_ROUTER(state, name) {
      for (let route of state.routerList) {
        if (route.name == name) {
          if (!route.isActive) {
            route.isActive = true;
          }
        } else if (route.isActive) {
          route.isActive = false;
        }
      }
      return;
    },
    // 路由栏 - 删除其他选项
    DEL_ROUTER_OTHER(state) {
      state.routerList = state.routerList.filter((item) => {
        return item.isActive;
      });
      return;
    },
    // 路由栏 - 删除全部选项
    DEL_ROUTER_ALL(state) {
      state.routerList = [];
      return;
    },

    // 修改导航栏
    CHANGE_MENU(state, data) {
      for (let item of state.sidebarMenu) {
        let isShow = false;
        item.children &&
          item.children.forEach((vv) => {
            // console.log(vv.name, "--name")
            // console.log(data[vv.name], "dta")
            if (data[vv.name].isShow) {
              isShow = true;
              vv.isShow = true;
            }
          });
        item.isShow = isShow;
      }
    },
  },

  actions: {
    // 获取用户信息
    // getTest({ commit }) {
    //   return new Promise((resolve, reject) => {
    //     getInfo()
    //       .then((response) => {
    //         console.log(151515);
    //         const userInfo = response.data;
    //         commit("SET_USERINFO", userInfo);
    //         resolve(response);
    //       })
    //       .catch((error) => {
    //         reject(error);
    //       });
    //   });
    // },
  },
};

export default dict;
